home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3.iso
/
chapte19
/
ex1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-13
|
3KB
|
60 lines
// ex1.c - Create key example.
#include <windows.h>
#include <winreg.h>
#include <genstub.c>
LRESULT FAR PASCAL WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_COMMAND: // process menu items
switch( wParam )
{
case IDM_TEST:
{
HKEY hKeyResult = 0;
DWORD dwDisposition = 0;
// Create "MyDoc" shell interface.
LONG lResult = RegCreateKeyEx( HKEY_CLASSES_ROOT,
"MyDoc\\shell\\&Test\\command",
0, "", REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL,
&hKeyResult, &dwDisposition );
// Program the registry to use Notepad to open the document.
if ( lResult == ERROR_SUCCESS )
{
lResult = RegSetValueEx( hKeyResult, NULL, 0, REG_SZ,
"NotePad %1",
lstrlen( "NotePad %1" ) );
RegCloseKey( hKeyResult ); // close MyDoc key.
}
// Create .MDC file extension connection.
lResult = RegCreateKeyEx( HKEY_CLASSES_ROOT, ".MDC",
0, "", REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL,
&hKeyResult, &dwDisposition );
// Connect .MDC with MyDoc type.
if ( lResult == ERROR_SUCCESS )
{
// Set the value of the .MDC key to "MyDoc".
lResult = RegSetValueEx( hKeyResult, NULL, 0, REG_SZ, "MyDoc",
lstrlen( "MyDoc" ) );
RegCloseKey( hKeyResult );
}
}
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default: // default windows message processing
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return( 0L );
}